package com.fastCms.business.frame.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fastCms.business.frame.constant.CommonConst;
import com.fastCms.business.frame.pojo.PageParam;
import com.fastCms.business.frame.pojo.entity.CloudOrganize;
import com.fastCms.business.frame.daos.CloudOrganizeMapper;
import com.fastCms.business.frame.pojo.po.QueryOrganizePO;
import com.fastCms.business.frame.service.CloudOrganizeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 平台组织结构表 服务实现类
 * </p>
 *
 * @author liusq
 * @since 2019-05-26
 */
@Service
public class CloudOrganizeServiceImpl extends ServiceImpl<CloudOrganizeMapper, CloudOrganize> implements CloudOrganizeService {

    public CloudOrganize findByOrganizeCode(String organizeCode) {
        QueryWrapper<CloudOrganize> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state", CommonConst.STATE.VALID);
        queryWrapper.eq("organize_code", organizeCode);
        return this.getOne(queryWrapper);
    }

    @Override
    public CloudOrganize findById(String id) {
        QueryWrapper<CloudOrganize> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state", CommonConst.STATE.VALID);
        queryWrapper.eq("id", id);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<CloudOrganize> findByQueryOrganizePO(PageParam<QueryOrganizePO> queryOrganizePO) {
        QueryWrapper<CloudOrganize> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(queryOrganizePO.getQueryFields().getOrganizeName())) {
            queryWrapper.like("organize_name", queryOrganizePO.getQueryFields().getOrganizeName());
        }

        queryWrapper.eq("state", CommonConst.STATE.VALID);
        queryWrapper.eq("pa_organize_code", queryOrganizePO.getQueryFields().getOrganizeCode());
        queryWrapper.orderByDesc("create_time");
        List<CloudOrganize> list = this.list(queryWrapper);
        return list;
    }

    @Override
    public CloudOrganize findByPhone(String phone) {
        QueryWrapper<CloudOrganize> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state", CommonConst.STATE.VALID);
        queryWrapper.eq("phone", phone);
        return this.getOne(queryWrapper);
    }

    @Override
    public CloudOrganize findByOrganizeName(String organizeName) {
        QueryWrapper<CloudOrganize> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state", CommonConst.STATE.VALID);
        queryWrapper.eq("organize_name", organizeName);
        return this.getOne(queryWrapper);
    }

}
